﻿using CefSharp;
using System;
using System.Collections;
using System.Collections.Concurrent;

namespace Web_rongmeiti_sys.PublishToRongMeiTi
{
    /// <summary>
    /// Reponse响应文本处理
    /// </summary>
    /// 创建时间：2023-5-26 11:32:32，作者：王浩力
    public class MyResponseFilter : IResponseFilter
    {

        public List<byte> buffer = new List<byte>();

        public void Dispose()
        {
            //throw new NotImplementedException();
        }

        public FilterStatus Filter(Stream dataIn, out long dataInRead, Stream dataOut, out long dataOutWritten)
        {
            try
            {
                if (dataIn == null || dataIn.Length == 0)
                {
                    dataInRead = 0;
                    dataOutWritten = 0;
                    return FilterStatus.Done;
                }
                dataIn.CopyTo(dataOut);
                dataOut.Seek(0, SeekOrigin.Begin);
                dataIn.Seek(0, SeekOrigin.Begin);

                byte[] bs = new byte[dataIn.Length];
                dataIn.Read(bs, 0, bs.Length);
                buffer.AddRange(bs);              

                dataInRead = dataIn.Length;
                dataOutWritten = dataIn.Length;
                return FilterStatus.NeedMoreData;
            }
            catch (Exception ex)
            {
                var exIn = ex.InnerException ?? ex;
                LogHelpter.AddLog($"MyResponseFilter处理异常{exIn.Message}", null, "error_MyResponseFilter");
            }
            dataInRead = dataIn.Length;
            dataOutWritten = dataOut.Length;
            return FilterStatus.Done;
        }

        public bool InitFilter()
        {
            //throw new NotImplementedException();
            return true;
        }
    }
}
